package com.tmri.clean.init;

import com.tmri.clean.until.EncryptUtil;
import org.apache.tomcat.jdbc.pool.DataSource;
import org.springframework.jdbc.core.JdbcTemplate;

import java.util.Properties;

/**
 * @Description TODO
 * @Date 2021/10/19 11:24
 * @Created by xielx
 */
public class OracleHandler {
    private static DataSource DATA_SOURCE;
    private static JdbcTemplate jdbcTemplate;
    private static final String key = "TMRI_DATASOURCE_USERNAME_PASSWORD_KEY";

    public static void init(Properties properties) throws Exception {
        DATA_SOURCE = new DataSource();
        DATA_SOURCE.setUrl(properties.getProperty("jdbc.url"));
        DATA_SOURCE.setDriverClassName("oracle.jdbc.driver.OracleDriver");
        DATA_SOURCE.setUsername(EncryptUtil.decryptMessage(properties.getProperty("jdbc.username"), key));
        DATA_SOURCE.setPassword(EncryptUtil.decryptMessage(properties.getProperty("jdbc.password"), key));
        DATA_SOURCE.setDefaultAutoCommit(true);
        jdbcTemplate = new JdbcTemplate(DATA_SOURCE);
    }

    public static JdbcTemplate getJdbcTemplate() {
        return jdbcTemplate;
    }

}
